package com.zhu.commentstatisticspublisher.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zhu.commentstatisticspublisher.bean.EvaluationWindow;
import com.zhu.commentstatisticspublisher.service.ClickHouseSelectService;
import com.zhu.commentstatisticspublisher.utils.GetDateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * clickhouse 查询
 */
@RestController
@RequestMapping("/zhu/comment/olap")
public class ClickHouseSelectController {

    @Autowired
    private ClickHouseSelectService clickHouseSelectService;

    @RequestMapping("/count")
    public String getEvaluationWindow(
            @RequestParam(value = "date",defaultValue = "0") String startTime,
            @RequestParam(value = "date",defaultValue = "0") String endTime){
        if ("0".equals(startTime)){
            if("0".equals(endTime)){
                startTime = GetDateUtil.dateFormat(System.currentTimeMillis() - 24 * 60 * 60 * 1000L);
                endTime = GetDateUtil.dateFormat(System.currentTimeMillis());
            }else {
                endTime = GetDateUtil.toYmdHms(GetDateUtil.toTs(startTime,false));
            }
        }
        EvaluationWindow evaluationWindow = clickHouseSelectService.getEvaluationWindow(startTime, endTime);
        JSONObject result = new JSONObject();
        result.put("nodes",0);
        result.put("stt",evaluationWindow.getStartTime());
        result.put("edt",evaluationWindow.getEndTime());
        result.put("count",evaluationWindow.getCount());
        return result.toJSONString();
    }


    @RequestMapping("/keyword")
    public String getEvaluationKeyword(@RequestParam(value = "date",defaultValue = "0") String date){
        return  null;
    }


}
